var orids=getvl("orid");
var zongjine=0;
$(function(){
	 if(orids!=""){
        slectOrdermeliy(orids);	 	
	 }else{
	 	//alert("异常");
	 }
});

function slectOrdermeliy(orids){
		  $("#zhanghuxinxi").html("&yen;"+0);
	       $("#zhifugoods").html("");
	$.ajax({
		url: urlcore + "/api/order/orderId?orderId="+orids,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//alert(JSON.stringify(data.data))
				var zongjine=data.data.paymoney+data.data.freightmoney;
				var zhifugoods='<li>'+
						'			商品数量'+
						'			<h6>共'+data.data.goodsNumber+'件</h6>'+
						'		</li>'+
						'		<li>'+
						'			商品总价'+
						'			<h6>&yen;'+data.data.ordermoney+'</h6>'+
						'		</li>'+
						'		<li>'+
						'			总运费'+
						'			<h6>&yen;'+data.data.freightmoney+'</h6>'+
						'		</li>'+
						'		<li class="zhifu_dingdan_da">'+
						'			订单总价'+
						'			<h6><em>&yen;'+zongjine+'</em></h6>'+
						'		</li>';
            zhanghu(uuuuid);
	          $("#zhifugoods").append(zhifugoods);
	  
			}
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});	

}



function zhanghu(uuuuid){
	  $("#zhanghuxinxi").html("&yen;"+0);
	  $("#zhanghuss").val(0);
	  if(uuuuid!=""){
	$.ajax({
		url: urlcore + "/api/userAccount/selectOness?userId="+uuuuid,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
			///	alert(JSON.stringify(data.data));
			     $("#zhanghuxinxi").html("&yen;"+data.data.balanceMoney);
			     $("#zhanghuss").val(data.data.balanceMoney);
			}else{
				alert("异常 ");
			}
		},
		error: function() {
			/* Act on the event */
			alert("error");
		}
	});
}
}


function zhifu(){
	     var val=$('input:radio[name="radio1"]:checked').val();
	     if(val==null){
	     	alert("未选择支付方式");
	     	return false;
	     }else{
	     	 if(val=="01"){
	     	 	  yuezhifu();
	     	 }else if(val=="02"){
	     	 	  // alert("微信支付");
	     	 	 callpay();
	     	   // zhifuweixin();
	     	 }
	     }
}

//微信支付
function  zhifuweixin(){
	     if(orids!="" && uuuuid!=""){
	       $.ajax({
					url: urlcore+"/api/pay/wxpay2?isXcx=1&recoedType=1&orderId="+orids+"&userId="+uuuuid,
					type: "get",
					dataType: 'json',
					contentType: "application/json;charset=utf-8",
					success:function(data){		
					var d = data.data;
					console.log(data)
					 WeixinJSBridge.invoke(
					    'getBrandWCPayRequest',
					    {
				           "appId":d.appId,    
				           "timeStamp":d.timeStamp,        
				           "nonceStr":d.nonceStr, 
				           "package":d.package,     
				           "signType":"MD5",        
				           "paySign":d.paySign 
				       },
					    function (res){
					         if(res.err_msg == "get_brand_wcpay_request:ok" ) {
					        //alert("支付成功");
                      window.location.href ="http://wx.jiagangwangluo.com/wx/buy/12.0.0buy_wode.html";
					         }else{
					         	//alert("支付失败");
					         	  window.location.href = document.referrer;
					         }
					    });
				    },
						error:function() {
							/* Act on the event */
							alert("error");
						}
				});	
				
	   }
}


 function callpay(){
		if (typeof WeixinJSBridge == "undefined"){
			    if (document.addEventListener){
		         document.addEventListener('WeixinJSBridgeReady', zhifuweixin,false);
			    }else if (document.attachEvent){
              document.attachEvent('WeixinJSBridgeReady', zhifuweixin);
	          	document.attachEvent('onWeixinJSBridgeReady', zhifuweixin);
			    }
			    }else{
			        zhifuweixin();
			    }
			    
			    
			}
 
function gotoyuezhifu(paye){
	$.ajax({
		url: urlcore+"/api/user/yanzhengjiumima?paye="+paye,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				yuezhifu();
			}else{
				alert("支付失败");
			}
		},
		error: function() {
			/* Act on the event */
			alert("error");
		}
	});
	
	
	
	
}



//余额支付
function yuezhifu(){
	  if(uuuuid!=""){
	  		$.ajax({
					url: urlcore + "/api/user/selectUserInfoByUserId?id="+uuuuid,
					type: "get",
					dataType: 'json',
					contentType: "application/json;charset=utf-8",
					success: function(data) {
						console.log(data)
						if(data.success == true) {
							if(data.data!=null && data.data!=""){
								if(data.data.payPwd!="" || data.data.payPwd!=null){
										sessionStorage.setItem("orids",orids);
									  window.location.href="zhifumimatankuang.html";
								}else{
									alert("未设置支付密码");
										 window.location.href="../buy/12.7.0shezhi.html";
								}
							}
						}
					},
					error: function() {
						/* Act on the event */
						alert("error");
					}
				});
	  }

	
	/*
		var url2="";
		if(orids!=null&& orids!="" && uuuuid!=""){
	url2="/api/pay/balanceMoney2?userId="+uuuuid+"&orderId="+orids;
		}
      if(url2!=""){
	$.ajax({
		url: urlcore+url2,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				//alert("支付成功");
					window.location.href = document.referrer;
			}else{
				alert("支付失败");
			}
		},
		error: function() {
			/* Act on the event 
			alert("error");
		}
	});
	}*/
}

/*
function zhifuchenggong(){
   	  $.ajax({
      url: urlcore+"/api/order/cancelOrder?orid="+orids,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
			  alert("支付成功");
			   if(uuuuid!=''){
			   	 window.location.href="12.8.0buy_dingdan_daifahuo.html?id="+uuuuid;
			   }else{
			   	  window.location.href="../index.html";
			   }
			 
				}
		/*console.log(goodslist);
			},
			error: function() {
				alert("error");
			}
		});
}
*/